<?php
defined('_JEXEC') or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
class SanPhamViewDetail extends JView
{
	function display($tpl = null)
	{
		global $mainframe; 

		if($this->getLayout() == 'default' or $this->getLayout() == 'default2') {
			$this->_display($tpl);
			return;
		}
		parent::display($tpl);
	}
	function _display($tpl)
	{
		global $mainframe, $option;
		$db		=& JFactory::getDBO();
		$uri 	=& JFactory::getURI();
		$model	=& $this->getModel();

		$lists = array();
		$detail	=& $this->get('data');			
		$temp2 = $this->getListCategory('0','');		
		
		//$lists['sel']=JHTML::_('select.genericList',$temp2,'parent', 'class="inputbox" '.'','id','title',$detail->parent);
		$lists['sel'] = $this->createSel($temp2,$detail->parent);
		
				
		
		//$list[] = JHTML::_('select.option','','--Select--');	
		/*$color = $this->getListColor();
		$lists['color'] = JHTML::_('select.genericList', $color, 'color', 'class="inputbox" '.'','id','name',$detail->color);
		
		$color1 = $this->getListColor();
		$lists['color1'] = JHTML::_('select.genericList', $color1, 'color1', 'class="inputbox" '.'','id','name',$detail->color1);
		
		$color2 = $this->getListColor();
		$lists['color2'] = JHTML::_('select.genericList', $color2, 'color2', 'class="inputbox" '.'','id','name',$detail->color2);*/
		//////////////////////////////////////////////////////	
		/*$theloaisize = array( '0' => array('value' => '0', 'text' => '-- Chọn --'),
						'1' => array('value' => '1', 'text' => 'Quần'),
						'2' => array('value' => '2', 'text' => 'Áo'),
						'3' => array('value' => '3', 'text' => 'Giầy')						
						);*/
		// build list of categories
		// build the html select list
		$lists['published'] 		= JHTML::_('select.booleanlist',  'published', 'class="inputbox"', $detail->published );
		//$lists['status'] 			= JHTML::_('select.booleanlist',  'status', 'class="inputbox"', $detail->status );		
		//$lists['frontpage'] 		= JHTML::_('select.booleanlist',  'frontpage', 'class="inputbox"', $detail->frontpage );
		//$lists['saleyesno'] 		= JHTML::_('select.booleanlist',  'saleyesno', 'class="inputbox"', $detail->saleyesno );
		//$lists['theloaisize'] = JHTML::_('select.genericlist',$theloaisize, 'theloaisize', 'class="inputbox" '. '','value', 'text', $detail->theloaisize);
				
		$this->assignRef('lists',		$lists);
		$this->assignRef('detail',		$detail);	
		
		
		parent::display($tpl);
	}
	private function getListCategory($id,$text){
		global $category;
		$db =&JFactory::getDBO();
		$query = 'select * from #__category where parent_id= '.$id.' ORDER BY ordering ';
		$db->setQuery($query);
		$rows = $db->loadAssocList();
		foreach($rows as $key=>$value){
			$value['title'] = substr($text.'|_ '.$value['title'],2);
			$value['alt'] = '123';
			$category[] = $value;
			$this->getListCategory($value['id'],$text.'. &nbsp;&nbsp;&nbsp;&nbsp;');
		} 
		return $category;
	}
	function createSel($arr,$id){
		if(count($arr)){
			foreach($arr as $key =>$val){
				$parent[] = $val['parent_id'];
			}
			$str = '<select id="parent" name="parent" class="inputbox" >';
			foreach($arr as $key =>$value){				
				if(in_array($value['id'],$parent)){
					$str.='<option value="'.$value['id'].'" disabled="disabled">'.$value['title'].'</option>';	
				}else{
					if($value['id']==$id)
						$str.='<option value="'.$value['id'].'" selected="selected">'.$value['title'].'</option>';	
					else
						$str.='<option value="'.$value['id'].'">'.$value['title'].'</option>';	
				}
			}
			$str.='</select>';
		}
		return $str;
		
	}
	/*function getListColor(){
		$db=& JFactory::getDBO();
		$db->setQuery("SELECT * FROM #__color WHERE published=1");
		return $db->loadObjectList();
	}*/
	
}